using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EagleController : Enemy
{
    // Start is called before the first frame update
    private Rigidbody2D rb;

    public Transform topPoint, bottomPoint;

    public float speed;

    private float topY,bottomY;

    private bool FaceLeft;
    protected virtual void Start()
    {
        base.Start();
        rb = GetComponent<Rigidbody2D>();
        topY = topPoint.transform.position.y;
        bottomY = bottomPoint.transform.position.y;
        Destroy(topPoint.gameObject);
        Destroy(bottomPoint.gameObject);
    }

    // Update is called once per frame
    void Update()
    {
      if(transform.position.y >= topY){
        FaceLeft = true;
      }
      if(transform.position.y <= bottomY){
        FaceLeft = false;
      }
        
    }
    void FixedUpdate(){
      Movement();
    }

    void Movement(){
      if(FaceLeft){
        rb.velocity = new Vector2(0, -speed);
      }else{
        rb.velocity = new Vector2(0, speed);
      }

    }

}
